using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;


using Material.Object;
using Material.DAL;
namespace Material.Entity
{
	public class TblTransPemBarangDTLEntity
	{
		private Accessor accessor;
		private string connString;

		public TblTransPemBarangDTLEntity (string _connString)
		{
			 this.connString = _connString;
		}

		public int Insert(TblTransPemBarangDTL tbltranspembarangdtl)
		{
			 int result = -1;
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblTransPemBarangDTL_Insert";
			 accessor.CommandType = CommandType.StoredProcedure;
			 accessor.Add("@IdTransDTL" ,tbltranspembarangdtl.IdTransDTL );
			 accessor.Add("@IdTransHDR" ,tbltranspembarangdtl.IdTransHDR );
			 accessor.Add("@TglBeli" ,tbltranspembarangdtl.TglBeli );
			 accessor.Add("@Jumlah" ,tbltranspembarangdtl.Jumlah );
			 accessor.Add("@Harga1" ,tbltranspembarangdtl.Harga1 );
			 accessor.Add("@Harga2" ,tbltranspembarangdtl.Harga2 );
			 accessor.Add("@Harga3" ,tbltranspembarangdtl.Harga3 );
			 accessor.Add("@TotalHarga" ,tbltranspembarangdtl.TotalHarga );
			 accessor.Add("@Created" ,tbltranspembarangdtl.Created );
			 accessor.Add("@CreatedBy" ,tbltranspembarangdtl.CreatedBy );
			 accessor.Add("@Modified" ,tbltranspembarangdtl.Modified );
			 accessor.Add("@ModifiedBy" ,tbltranspembarangdtl.ModifiedBy );

			 result = Excutor.ExecuteNonQuery(accessor);
			 if (result != -1)
				 accessor.CommitTransaction();
			 else
				 accessor.RollBackTransaction();
			 return result;
		}

		public int Update(TblTransPemBarangDTL tbltranspembarangdtl)
		{
			 int result = -1;
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblTransPemBarangDTL_Update";
			 accessor.CommandType = CommandType.StoredProcedure;
			 accessor.Add(@"IdTransDTL" ,tbltranspembarangdtl.IdTransDTL );
			 accessor.Add(@"IdTransHDR" ,tbltranspembarangdtl.IdTransHDR );
			 accessor.Add(@"TglBeli" ,tbltranspembarangdtl.TglBeli );
			 accessor.Add(@"Jumlah" ,tbltranspembarangdtl.Jumlah );
			 accessor.Add(@"Harga1" ,tbltranspembarangdtl.Harga1 );
			 accessor.Add(@"Harga2" ,tbltranspembarangdtl.Harga2 );
			 accessor.Add(@"Harga3" ,tbltranspembarangdtl.Harga3 );
			 accessor.Add(@"TotalHarga" ,tbltranspembarangdtl.TotalHarga );
			 accessor.Add(@"Created" ,tbltranspembarangdtl.Created );
			 accessor.Add(@"CreatedBy" ,tbltranspembarangdtl.CreatedBy );
			 accessor.Add(@"Modified" ,tbltranspembarangdtl.Modified );
			 accessor.Add(@"ModifiedBy" ,tbltranspembarangdtl.ModifiedBy );

			 result = Excutor.ExecuteNonQuery(accessor);
			 if (result != -1)
				 accessor.CommitTransaction();
			 else
				 accessor.RollBackTransaction();
			 return result;
		}

		public int Delete(TblTransPemBarangDTL tbltranspembarangdtl)
		{
			 int result = -1;
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblTransPemBarangDTL_Delete";
			 accessor.CommandType = CommandType.StoredProcedure;
			 accessor.Add(@"IdTransDTL" ,tbltranspembarangdtl.IdTransDTL);

			 result = Excutor.ExecuteNonQuery(accessor);
			 if (result != -1)
				 accessor.CommitTransaction();
			 else
				 accessor.RollBackTransaction();
			 return result;
		}

		public TblTransPemBarangDTL GetDataByID(TblTransPemBarangDTL tbltranspembarangdtl)
		{
			 TblTransPemBarangDTL result = new TblTransPemBarangDTL();
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblTransPemBarangDTL_SelectByID";
			 accessor.CommandType = CommandType.StoredProcedure;
			 accessor.Add(@"IdTransDTL" ,tbltranspembarangdtl.IdTransDTL);

			 SqlDataReader rdr = Excutor.GetDataReader(accessor);
			 if (rdr.HasRows)
			 {
				 while (rdr.Read())
					 {
						 result.IdTransDTL = rdr.GetInt32(0);
						 result.IdTransHDR = rdr.GetInt32(1);
						 result.TglBeli = rdr.GetDateTime(2);
						 result.Jumlah = rdr.GetInt32(3);
						 result.Harga1 = rdr.GetDecimal(4);
						 result.Harga2 = rdr.GetDecimal(5);
						 result.Harga3 = rdr.GetDecimal(6);
						 result.TotalHarga = rdr.GetDecimal(7);
						 result.Created = rdr.GetDateTime(8);
						 result.CreatedBy = rdr.GetString(9);
						 result.Modified = rdr.GetDateTime(10);
						 result.ModifiedBy = rdr.GetString(11);
					  }
			}
			 return result;
		}

		public List<TblTransPemBarangDTL> GetDataAll()
		{
			 List<TblTransPemBarangDTL> result = new List<TblTransPemBarangDTL>();
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblTransPemBarangDTL_SelectAll";
			 accessor.CommandType = CommandType.StoredProcedure;

			 SqlDataReader rdr = Excutor.GetDataReader(accessor);
			 if (rdr.HasRows)
			 {
				 while (rdr.Read())
					 {
						 TblTransPemBarangDTL obj = new TblTransPemBarangDTL();
						 obj.IdTransDTL = rdr.GetInt32(0);
						 obj.IdTransHDR = rdr.GetInt32(1);
						 obj.TglBeli = rdr.GetDateTime(2);
						 obj.Jumlah = rdr.GetInt32(3);
						 obj.Harga1 = rdr.GetDecimal(4);
						 obj.Harga2 = rdr.GetDecimal(5);
						 obj.Harga3 = rdr.GetDecimal(6);
						 obj.TotalHarga = rdr.GetDecimal(7);
						 obj.Created = rdr.GetDateTime(8);
						 obj.CreatedBy = rdr.GetString(9);
						 obj.Modified = rdr.GetDateTime(10);
						 obj.ModifiedBy = rdr.GetString(11);
						 result.Add(obj);
					  }
			}
			 return result;
		}

	}
}
